package com.itheima.shop.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.itheima.shop.entity.OrderItem;

public interface OrderItemMapper {
	@Insert("insert into tab_orderitem(orderitemid,count,subtotal,pid,oid) values(#{orderitemid},#{count},#{subtotal},#{product.pid},#{order.oid})")
	@Options(useGeneratedKeys = true, keyProperty = "orderitemid")
	public int insert(OrderItem orderItem);

	@Select("select " + "tab_order.*," + "tab_orderitem.subtotal," + "tab_orderitem.pid," + "tab_orderitem.orderitemid,"
			+ "tab_orderitem.count " + "from tab_order "
			+ "join tab_orderitem on tab_order.oid = tab_orderitem.oid where tab_order.oid = #{oid}")
	@Results(value = { @Result(column = "oid", property = "order.oid"), @Result(column = "ordertime", property = "order.ordertime"),
			@Result(column = "total", property = "order.total"), @Result(column = "state", property = "order.state"),
			@Result(column = "address", property = "order.address"), @Result(column = "name", property = "order.name"),
			@Result(column = "telephone", property = "order.telephone"), @Result(column = "uid", property = "order.user.uid") })
	public List<OrderItem> findByOid(int oid);
}
